package com.ning.memoryleak.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.ning.memoryleak.R;
import com.ning.memoryleak.bean.ProfitBean;

import java.util.List;

/**
 * @作者: njb
 * @时间: 2019/11/28 12:01
 * @描述: 跑马灯特效的Adapter
 */
public class MarqueeAdapter extends  RecyclerView.Adapter<MarqueeAdapter.ViewHolder> {
    private Context mContext;
    private List<ProfitBean> mDatas;

    public MarqueeAdapter(Context mContext, List<ProfitBean> mDatas) {
        this.mContext = mContext;
        this.mDatas = mDatas;
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_marquee,parent, false);
        ViewHolder myViewHolder = new ViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.itemView.setTag(position);
        ProfitBean profitBean = mDatas.get(position);
        holder.textView.setText(profitBean.getName());
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        TextView textView;

        ViewHolder(View view) {
            super(view);
            textView = view.findViewById(R.id.tv_profit);
        }
    }


}
